• 0

Horizontal scrolling div box


Question

I want to have a 'box' on my web page which scrolls horizontally.

The contents of the box will have images. There could be one image (then there will be no scrolling) or there could be 8 images (and there will need to be a horizontal scroll bar).

I have managed to do something like it having a div within a div

The outer div is just one which is about 700px - width of the web page

I set the inner div to a width of about 1790px - that works find if its got the 8 images. However, if its got just one image it still has the horizontal scroll bar.

Any ideas??

Link to comment
https://www.neowin.net/forum/topic/567244-horizontal-scrolling-div-box/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

You can try something like

<div style="overflow:auto; width:700px;">
	<div style="width:1790px;">
		{images here}
	</div>
</div>

  • 0

the solution requires javascript, because the white-space:nowrap; CSS rendering is not going to work on inline block elements. They will always wrap unless the containing DIV is set to a width value large enough to let all inline block elements float left.

so: in CSS you set the images (your inline block elements) to {float:left;} and give them a static width like {width:78px;}

in JAVASCRIPT you calculate the number of elements you have in the scoller (8 in this case).

then you multiply that by the width of your elements.

var els = 8;

var elwidth = 78;

var scrollwidth = els*elwidth+"px";

document.all.getElementById("scroller").widthidth;

I haven't tested this because I use jquery most of the time, but in principle it's the only way to make this work.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.